﻿using System;
using System.Threading;

namespace Skynet.CommonLibrary.ThreadRefreshTime.StrateGy
{
    /// <summary>
    /// Timer时间控件
    /// </summary>
    ///<remarks>
    /// 作者：         李志强
    /// 开发时间：  2011-03-28
    /// </remarks>
    public class ThreadTimerStrategy : IThreadStrategy
    {
        Timer _time;
        #region IThreadSerategy 成员

        public void StartWork(Action workAction,int interval)
        {
            if (workAction == null)
                return;

            //线程 时间  利用线程池
            _time = new Timer(o => workAction(),
            null,
            100,
            interval);
        }

        public void StopWork()
        {
            if (_time != null)
            {
                _time.Change(-1, -1);
                _time.Dispose();
                _time = null;
            }
        }

        #endregion
    }
}
